<template>
  <div>
    <div id="main" style="width: 600px; height: 400px"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {
      list: [],
    };
  },
  methods: {
    ...mapActions({
      reqcatelist: "cate/reqchangelist",
    }),
  },
  computed: {
    ...mapGetters({
      catelist: "cate/list",
    }),
  },
  watch: {
    catelist: {
      deep: true,
      handler() {
        var myChart = echarts.init(document.getElementById("main"));

        // 指定图表的配置项和数据
        var option = {
          title: {
            text: "商品分类",
          },
          tooltip: {},
          legend: {
            data: ["数量"],
          },
          xAxis: {
            data: this.catelist.map(item=>item.catename),
          },
          yAxis: {},
          series: [
            {
              name: "数量",
              type: "line",
              data: this.catelist.map(item=>item.children.length),
            },
          ],
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
      },
    },
  },
  mounted() {
    this.reqcatelist();

    // console.log(this.list);
  },
};
</script>

<style lang="less">
</style>